import { Http } from "./http.js"
import {apis, localVersion} from "../global/config.js"
import { errTips } from "./http_interceptor.js"
import { Throwable } from "../err_handle/throwable.js"
import { compareVersion } from "../utils/utils.js"

export class RequestCenter extends Http {
	
	//测试接口 请忽略
	getList({start = 1, showLoading = false}) {
		return this.interceptor(() => {
			return this.get(apis.getList, {}, {start: start})
		}, {showLoading:showLoading})
	}
	
	//请求ftp上的一个json文件，仅用于获取服务器当前时间
	getServerTime({showLoading = true} = {}) {
		return this.interceptor(() => {
			return this.get(apis.getServerTime, {random: new Date().getTime()})
		}, {showLoading:showLoading})
	}
	
	//系统配置查询接口(根据类型查询)
	getSystemConfig(){
		return this.interceptor(() => {
			return this.get(apis.getSystemConfig + 1101).then(res => {
				let versonInfo = JSON.parse(res.content)
				let releaseVersion = versonInfo.version
				if(compareVersion(localVersion, releaseVersion) > 0) {
					  //本地版本号大于线上版本号，屏蔽发布功能和视频观看功能
					  return {
						  "isRelease": false,
						  "formSupport": false
					  }
				} else {
				  //本地版本号小于或等于线上版本号，开放发布功能和视频观看功能
				  return {
					  "isRelease": true,
					  "formSupport": true
				  }
				}
			})
		}, {showLoading: false})
	}
	
	//获取配置
	getConfig(){
		return this.interceptor(() => {
			return this.get(apis.getConfig, {random: new Date().getTime()}).then(res => {
				let releaseVersion = res.version
				if(compareVersion(localVersion, releaseVersion) > 0) {
					  //本地版本号大于线上版本号，屏蔽发布功能和视频观看功能
					  return {
						  "isRelease": false,
						  "formSupport": false
					  }
				} else {
				  //本地版本号小于或等于线上版本号，开放发布功能和视频观看功能
				  return {
					  "isRelease": true,
					  "formSupport": true
				  }
				}
			})
		}, {showLoading:false})
	}
	
	//文件上传
	uploadFile(filePath, params) {
		return this.interceptor(() => {
			return this.upload(apis.uploadFile, filePath, "file", {}, {}, params)
		}, {showLoading: true})
	}
	
	//字典分页列表
	getDictList(dictId){
		return this.interceptor(() => {
			return this.get(apis.getDictList, {dictId: dictId})
		}, {showLoading: true})
	}
	
	//获取APP版本
	getAppVersion(){
		return this.interceptor(() => {
			return this.post(apis.getAppVersion)
		}, {showLoading: true})
	}
	
	//-----------------------------------登录相关---------------------------------------------
	//发送验证码
	getSmsCode(params) {
		return this.interceptor(() => {
			return this.post(apis.getSmsCode, params)
		}, {showLoading: true})
	}
	//系统登陆
	userLogin(params){
		return this.interceptor(() => {
			return this.post(apis.userLogin, params)
		}, {showLoading: true})
	}
	
	//-----------------------------------用户相关---------------------------------------------
	//用户详情（根据Token获取）
	getPlayerInfo(){
		return this.interceptor(() => {
			return this.get(apis.getPlayerInfo)
		}, {showLoading: true})
	}
	
	//用户修改
	updatePlayerInfo(params){
		return this.interceptor(() => {
			return this.put(apis.updatePlayerInfo, params)
		}, {showLoading: true})
	}
	
	//-----------------------------------助教相关---------------------------------------------
	//助教用户列表
	getAssistantList(params){
		return this.interceptor(() => {
			return this.post(apis.getAssistantList, params)
		}, {showLoading: true})
	}
	
	//助教用户分页列表
	getAssistantPageList(params){
		return this.interceptor(() => {
			return this.post(apis.getAssistantPageList, params)
		}, {showLoading: true})
	}
	
	//助教详情
	getAssistantDetail(userId){
		return this.interceptor(() => {
			return this.get(apis.getAssistantDetail + userId)
		}, {showLoading: true})
	}
	
	//助教审核新增
	addAssistantInfo(params){
		return this.interceptor(() => {
			return this.post(apis.addAssistantInfo, params)
		}, {showLoading: true})
	}
	
	//助教信息修改
	updateAssistantDetail(params){
		return this.interceptor(() => {
			return this.put(apis.updateAssistantDetail, params)
		}, {showLoading: true})
	}
	
	//助教详情（根据Token获取）
	getAssistantDetailToken(){
		return this.interceptor(() => {
			return this.get(apis.getAssistantDetailToken)
		}, {showLoading: true})
	}
	
	//助教注销
	assistantWriteOff(params){
		return this.interceptor(() => {
			return this.put(apis.assistantWriteOff, params)
		}, {showLoading: true})
	}
	
	//助教获取下单二维码
	getAssistantQrCode(){
		return this.interceptor(() => {
			return this.get(apis.getAssistantQrCode)
		}, {showLoading: true})
	}
	
	//-----------------------------------广场视频---------------------------------------------
	//添加广场视频
	addSquareAssistantVideo(params){
		return this.interceptor(() => {
			return this.post(apis.addSquareAssistantVideo, params)
		}, {showLoading: true})
	}
	
	//获取广场视频
	getSquareAssistantVideo(params){
		return this.interceptor(() => {
			return this.post(apis.getSquareAssistantVideo, params)
		}, {showLoading: true})
	}
	
	//管理后台获取用户中心图片视频
	getAssistantVideoImage(params){
		return this.interceptor(() => {
			return this.post(apis.getAssistantVideoImage, params)
		}, {showLoading: true})
	}
	
	//删除视频或图片
	deleteVideoImage(params){
		return this.interceptor(() => {
			return this.post(apis.deleteVideoImage, params)
		}, {showLoading: true})
	}
	
	//-----------------------------------app-台球厅控制层---------------------------------------------
	//台球厅列表
	getPollHallList(params){
		return this.interceptor(() => {
			return this.post(apis.getPollHallList, params)
		}, {showLoading: true})
	}
	
	//台球厅分页列表
	getPollHallPageList(params){
		return this.interceptor(() => {
			return this.post(apis.getPollHallPageList, params)
		}, {showLoading: true})
	}
	
	//台球厅详情
	getPollHallDetail(pollId){
		return this.interceptor(() => {
			return this.get(apis.getPollHallDetail + pollId)
		}, {showLoading: true})
	}
	
	//-----------------------------------app订单接口层---------------------------------------------
	//订单新增
	addOrder(params){
		return this.interceptor(() => {
			return this.post(apis.addOrder, params)
		}, {showLoading: true})
	}
	
	//支付订单总价计算
	getOrderMoney(params){
		return this.interceptor(() => {
			return this.post(apis.getOrderMoney, params)
		}, {showLoading: true})
	}
	
	//支付唤醒
	rouseOrderPay(params){
		return this.interceptor(() => {
			return this.post(apis.rouseOrderPay, params)
		}, {showLoading: true})
	}
	
	//用户订单分页列表
	getUserOrderList(params){
		return this.interceptor(() => {
			return this.post(apis.getUserOrderList, params)
		}, {showLoading: true})
	}
	
	//助教订单分页列表
	getAssistantOrderList(params){
		return this.interceptor(() => {
			return this.post(apis.getAssistantOrderList, params)
		}, {showLoading: true})
	}
	
	//订单详情(根据主键id查询)
	getOrderDetail(id){
		return this.interceptor(() => {
			return this.get(apis.getOrderDetail + id)
		}, {showLoading: true})
	}

	//助教用户结束服务
	endOrderService(params){
		return this.interceptor(() => {
			return this.put(apis.endOrderService, params)
		}, {showLoading: true})
	}
	
	//助教用户开始服务
	startOrderService(params){
		return this.interceptor(() => {
			return this.put(apis.startOrderService, params)
		}, {showLoading: true})
	}
	
	//助教用户拒绝接单
	refuseOrder(params){
		return this.interceptor(() => {
			return this.put(apis.refuseOrder, params)
		}, {showLoading: true})
	}
	
	//接单
	receiveOrder(params){
		return this.interceptor(() => {
			return this.put(apis.receiveOrder, params)
		}, {showLoading: true})
	}
	
	//小程序订单续订
	renewOrder(params){
		return this.interceptor(() => {
			return this.post(apis.renewOrder, params)
		}, {showLoading: true})
	}
	
	//续订订单总价计算
	renewCalculateMoney(params){
		return this.interceptor(() => {
			return this.post(apis.renewCalculateMoney, params)
		}, {showLoading: true})
	}
	
	//-----------------------------------异常订单---------------------------------------------
	//异常订单新增
	abnormalSave(params){
		return this.interceptor(() => {
			return this.put(apis.abnormalSave, params)
		}, {showLoading: true})
	}
	
	//异常订单分页列表
	getAbnormalOrderList(params){
		return this.interceptor(() => {
			return this.post(apis.getAbnormalOrderList, params)
		}, {showLoading: true})
	}
	
	//异常订单详情
	getAbnormalOrderDetail(id){
		return this.interceptor(() => {
			return this.get(apis.getAbnormalOrderDetail + id)
		}, {showLoading: true})
	}
	
	//App订单新增
	addOrderApp(params){
		return this.interceptor(() => {
			return this.post(apis.addOrderApp, params)
		}, {showLoading: true})
	}
	
	
	//-----------------------------------app 钱包---------------------------------------------
	//用户钱包界面
	getUserWallet(){
		return this.interceptor(() => {
			return this.post(apis.getUserWallet)
		}, {showLoading: true})
	}
	
	//提现
	withdrawApply(params){
		return this.interceptor(() => {
			return this.post(apis.getUserWallet, params)
		}, {showLoading: true})
	}
	
	//提现记录
	withdrawApplyRecord(params){
		return this.interceptor(() => {
			return this.post(apis.withdrawApplyRecord, params)
		}, {showLoading: true})
	}
	
	//
	withdrawApplyDetail(id){
		return this.interceptor(() => {
			return this.get(apis.withdrawApplyDetail + id)
		}, {showLoading: true})
	}
	
	//账单流水
	incomeRecordList(params){
		return this.interceptor(() => {
			return this.post(apis.incomeRecordList, params)
		}, {showLoading: true})
	}
	
	//用户入账记录详情
	incomeRecordDetail(id){
		return this.interceptor(() => {
			return this.post(apis.incomeRecordDetail + id)
		}, {showLoading: true})
	}
	
	//-----------------------------------通用枚举类型---------------------------------------------
	//订单异常状态枚举获取
	getOrderAbnormalState(params){
		return this.interceptor(() => {
			return this.get(apis.getOrderAbnormalState, params)
		}, {showLoading: true})
	}
	
	//助教等级列表
	getGradeList(){
		return this.interceptor(() => {
			return this.post(apis.getGradeList)
		}, {showLoading: true})
	}
	
	//助教接单状态枚举
	getReceivingList(){
		return this.interceptor(() => {
			return this.get(apis.getReceivingList)
		}, {showLoading: true})
	}
	
	//-----------------------------------提现---------------------------------------------
	//用户提现申请
	withdrawApply(params){
		return this.interceptor(() => {
			return this.post(apis.withdrawApply, params)
		}, {showLoading: true})
	}
	
	//用户提现详情列表（分页）
	withdrawRecordList(params){
		return this.interceptor(() => {
			return this.get(apis.withdrawRecordList, params)
		}, {showLoading: true})
	}
	
	//用户提现详情列表
	withdrawRecordDetail(){
		return this.interceptor(() => {
			return this.get(apis.withdrawRecordDetail, params)
		}, {showLoading: true})
	}
	
	//-----------------------------------余额---------------------------------------------
	//用户余额详情（用户本身token）
	getBalanceInfo(params){
		return this.interceptor(() => {
			return this.get(apis.getBalanceInfo, params)
		}, {showLoading: true})
	}
	
	//App用户经纬度数据更新
	updateUserPosition(params){
		return this.interceptor(() => {
			return this.post(apis.updateUserPosition, params)
		}, {showLoading: true})
	}
	
	//用户收藏-取消收藏
	addLikeFavorite(params){
		return this.interceptor(() => {
			return this.post(apis.addLikeFavorite, params)
		}, {showLoading: true})
	}
	
	//用户点赞-取消点赞
	addCollect(params){
		return this.interceptor(() => {
			return this.post(apis.addCollect, params)
		}, {showLoading: true})
	}
	
	
	
}